<template>
  <div class="c-bg-sgray">
    <com-recommend :dataList="dataList" :dataStatus="dataStatus"></com-recommend>
  </div>
</template>

<script>
import ComRecommend from './comRecommend.vue'
import { utilJs } from "@/utils/common.js"
let pageIndex = 1;
const LIMIT = 20;
export default {
  name: 'RecommendList',
  components: {
    ComRecommend,
  },
  props: [],
  created() {
    utilJs.appShare(this);
  },
  data() {
    return {
      dataList: [],
      dataStatus: "HAS_MORE_DATA", //显示加载更多LOAD_MORE 加载中 LOADING 没有更多 NO_MORE_DATA
    }
  },

  methods: {
    getRecodeList() {
      if (this.dataStatus == 'LOADING') {
        return;
      }
      this.dataStatus = 'LOADING';
      utilJs.getMethod(`${global.apiurl}declares/getRefereeLists?page=${pageIndex}&limit=${LIMIT}`, (res) => {
        if (pageIndex == 1) {
          this.dataList = res.data;
        } else {
          this.dataList = [...this.dataList, ...res.data];
        }
        if (res.data && (res.data.length < LIMIT)) {
          this.dataStatus = pageIndex == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
        } else {
          this.dataStatus = 'HAS_MORE_DATA';
          pageIndex++;
        }
      },
        failRes => {
          this.dataStatus = 'DATA_ERROR';
        }
      );
    },
    //分享
    wechatShare() {
      utilJs.wechatConfig("", "", "", "", function () { });
    },
    //手机端分享
    appShare() {
      utilJs.appShareTrue("", "", "", "");
    },
    windowScrollFunction() {
      utilJs.handleLoading(() => {
        if (this.dataStatus == 'HAS_MORE_DATA' && this.liveList.length > 0) {
          this.getClockInList();
        }
      });
    },
  },
  activated() {
    setDocumentTitle('报单系统-推荐记录');// eslint-disable-line
    pageIndex = 1;
    this.dataList = [];
    this.dataStatus = 'HAS_MORE_DATA';
    this.getRecodeList();
    window.addEventListener('scroll', this.windowScrollFunction);
    this.wechatShare();
  },
  deactivated() {
    this.dataStatus = 'NO_MORE_DATA';
    window.removeEventListener('scroll', this.windowScrollFunction);
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
